﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.ServiceModel;
using System.Linq;
using System.Text;

namespace Faust.Andrew.MTG.Player.Shared
{    
    [DataContract]
    public class GameCard : Card
    {
        public GameCard()
        {
            Location = new Location();
            Counters = new ObservableCollection<Counter>();
            AttachedCards = new ObservableCollection<GameCard>();
        }

        private int _cardID;
        /// <summary>
        /// Unique targetPlayerID to represent an individual cardID within a gam
        /// </summary>
        [DataMember]
        public int CardID
        {
            get
            {
                return _cardID;
            }
            set
            {
                if (_cardID != value)
                {
                    _cardID = value;
                    FirePropertyChangedEvent("CardID");
                }
            }
        }

        private int _controllerID;
        /// <summary>
        /// Which player controls this cardID.
        /// </summary>
        [DataMember]
        public int ControllerID
        {
            get
            {
                return _controllerID;
            }
            set
            {
                if (_controllerID != value)
                {
                    _controllerID = value;
                    FirePropertyChangedEvent("ControllerID");
                }
            }
        }

        private Location _location;
        /// <summary>
        /// Location of the cardID on the GameState
        /// </summary>
        [DataMember]
        public Location Location
        {
            get
            {
                return _location;
            }
            set
            {
                if (_location != value)
                {
                    _location = value;
                    FirePropertyChangedEvent("Location");
                }
            }
        }

        private ObservableCollection<Counter> _counters;
        /// <summary>
        /// Any counters that are on the cardID such as power, toughness, storage, etc.
        /// </summary>
        [DataMember]
        public ObservableCollection<Counter> Counters
        {
            get
            {
                return _counters;
            }
            set
            {
                if (_counters != value)
                {
                    _counters = value;
                    FirePropertyChangedEvent("Counters");
                }
            }
        }

        private int _ownerID;
        [DataMember]
        public int OwnerID
        {
            get
            {
                return _ownerID;
            }
            set
            {
                if (_ownerID != value)
                {
                    _ownerID = value;
                    FirePropertyChangedEvent("OwnerID");
                }
            }
        }

        private CardState _state;
        [DataMember]
        public CardState State
        {
            get
            {
                return _state;
            }
            set
            {
                if (_state != value)
                {
                    _state = value;
                    FirePropertyChangedEvent("State");
                }
            }
        }

        private bool _isFaceDown;
        /// <summary>
        /// Whether or not the cardID is in play face down. Used for cardIDs that have Morph ability
        /// </summary>
        [DataMember]
        public bool IsFaceDown
        {
            get
            {
                return _isFaceDown;
            }
            set
            {
                if (_isFaceDown != value)
                {
                    _isFaceDown = value;
                    FirePropertyChangedEvent("IsFaceDown");
                }
            }
        }

        private string _modifierText;
        /// <summary>
        /// Used to indicate any modifier that is applied to the cardID that may not be readily apparent. For example it may have been given flying or "protection from"
        /// </summary>
        /// <remarks>This is particularly usefule for "Tokens" that are put in to play. This text would tell what type of Token it is.</remarks>
        [DataMember]
        public string ModifierText
        {
            get
            {
                return _modifierText;
            }
            set
            {
                if (_modifierText != value)
                {
                    _modifierText = value;
                    FirePropertyChangedEvent("ModifierText");
                }
            }
        }

        private bool _isToken;
        /// <summary>
        /// Used to indicate whether or not a cardID is a Token cardID.
        /// </summary>
        /// <remarks>
        /// Token cardIDs are often put in to play due to some enchantment or creature ability. They will often take the form of "Put a 1/1 White Soldier in to play"
        /// Token cardIDs have no MultiverseID as they aren't a cardID. This flag tells the clients not to try to look up the cardID.
        /// </remarks>
        [DataMember]
        public bool IsToken
        {
            get
            {
                return _isToken;
            }
            set
            {
                if (_isToken != value)
                {
                    _isToken = value;
                    FirePropertyChangedEvent("IsToken");
                }
            }
        }

        private string _tokenImageKey;
        [DataMember]
        public string TokenImageKey
        {
            get { return _tokenImageKey; }
            set
            {
                if (_tokenImageKey != value)
                {
                    _tokenImageKey = value;
                    FirePropertyChangedEvent("TokenImageKey");
                }
            }
        }
        

        private ObservableCollection<GameCard> _attachedCards;
        /// <summary>
        /// Any cardIDs that are attached to this cardID such as enchantments
        /// </summary>
        [DataMember]
        public ObservableCollection<GameCard> AttachedCards
        {
            get
            {
                return _attachedCards;
            }
            set
            {
                if (_attachedCards != value)
                {
                    _attachedCards = value;
                    FirePropertyChangedEvent("AttachedCards");
                }
            }
        }
    }
}
